﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace FigureDraw
{
    public class StarShape : CommonShape
    {
        private Point[] arrPointStartShap;
        private Point centre;   //Tam duong tron
        private float radius;   //ban kinh duong tron

        public StarShape(StorageDevice sd)
            : base(sd)
        {
            arrPointStartShap = new Point[5];
        }

        public override void DrawToDevice(Form form)
        {
            this.KhoiTaoTruocKhiVe();
            centre.X = (this.BeginPoint.X + this.EndPoint.X) / 2;
            centre.Y = (this.BeginPoint.Y + this.EndPoint.Y) / 2;

            if(this.EndPoint.X - this.BeginPoint.X > this.EndPoint.Y - this.BeginPoint.Y)
                this.radius = (this.EndPoint.X - this.BeginPoint.X) / 2;
            else
                this.radius = (this.EndPoint.Y - this.BeginPoint.Y) / 2;

            float deta = (float)(72 * Math.PI / 180);
            float angle = 0;

            
            for (int i = 0; i < 5; i++)
            {
                this.arrPointStartShap[i].X = centre.X + (int)(radius * Math.Cos((double)(angle)));
                this.arrPointStartShap[i].Y = centre.Y + (int)(radius * Math.Sin((double)(angle)));

                angle += deta;
            }

            this.StorageDevice.drawLine(this.arrPointStartShap[0].X, this.arrPointStartShap[0].Y, 
                this.arrPointStartShap[2].X, this.arrPointStartShap[2].Y);
            this.StorageDevice.drawLine(this.arrPointStartShap[0].X, this.arrPointStartShap[0].Y,
                this.arrPointStartShap[3].X, this.arrPointStartShap[3].Y);
            this.StorageDevice.drawLine(this.arrPointStartShap[1].X, this.arrPointStartShap[1].Y,
                this.arrPointStartShap[3].X, this.arrPointStartShap[3].Y);
            this.StorageDevice.drawLine(this.arrPointStartShap[1].X, this.arrPointStartShap[1].Y,
                this.arrPointStartShap[4].X, this.arrPointStartShap[4].Y);
            this.StorageDevice.drawLine(this.arrPointStartShap[4].X, this.arrPointStartShap[4].Y,
                this.arrPointStartShap[2].X, this.arrPointStartShap[2].Y);
        }
    }
}
